import time

from ddt import ddt, data, unpack
from selenium import webdriver
from unittest import TestCase
from LoanData import LoanData
from LoanOperation import LoanOperation
from Web自动化测试.财务系统.代码.买入基金理财测试用例.FinanceOperation import FinanceOperation
from Web自动化测试.财务系统.代码.登陆测试.代码.LoginOperation import LoginOperation


@ddt
class TestLoan(TestCase):
    # @data(*LoanData.loandata1)
    # @unpack
    # def testLoan(self, username, password, money, times):
    #     driver = webdriver.Chrome()
    #     driver.get("http://localhost:90")
    #     driver.maximize_window()
    #
    #     # 调用登陆
    #     log = LoginOperation()
    #     log.login(driver, username, password)
    #     time.sleep(5)
    #     # 贷款前记录
    #     Loans = LoanOperation()
    #     loans = Loans.lookNews(driver)
    #     time.sleep(5)
    #
    #     # 贷款调用
    #     apply = Loans.applyLoan(driver, money, times)
    #     time.sleep(5)
    #     # 贷款后的记录查询
    #     loanb = Loans.lookNews(driver)
    #     time.sleep(5)
    #     if int(loans) != int(loanb) - 1:
    #         driver.save_screenshot(username + "---" + password + "---" + money + "---" + times + "---" + ".jpg")
    #     else:
    #         print("测试成功！")
    #     driver.quit()
    #     self.assertEqual(int(loans) + 1, int(loanb))

    @data(*LoanData.loandata2)
    @unpack
    def testMoney(self, username, password, money, times):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()

        # 调用登陆
        log = LoginOperation()
        log.login(driver, username, password)
        time.sleep(5)
        # 贷款前记录
        Loans = LoanOperation()
        time.sleep(5)

        result = Loans.applyMoneyError(driver, money, times)
        time.sleep(5)

        if result == "就借这么点钱吗？？？":
            print("测试成功！")
        else:
            driver.save_screenshot(username + "---" + password + "---" + money + "---" + times + "---" + ".jpg")
        driver.quit()
        self.assertEqual(result, "就借这么点钱吗？？？")

    @data(*LoanData.loandata3)
    @unpack
    def testMoney(self, username, password, money, times):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()

        # 调用登陆
        log = LoginOperation()
        log.login(driver, username, password)
        time.sleep(5)
        # 贷款前记录
        Loans = LoanOperation()
        time.sleep(5)

        result = Loans.applyMoneyError(driver, money, times)
        time.sleep(5)

        if result == "就借这么点钱吗？？？":
            print("测试成功！")
        else:
            driver.save_screenshot(username + "---" + password + "---" + money + "---" + times + "---" + ".jpg")
        driver.quit()
        self.assertEqual(result, "就借这么点钱吗？？？")

